home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-04
/
love4th.zip
/
COMPAT83.DOC
< prev
next >
Wrap
Text File
|
1991-10-01
|
4KB
|
109 lines
Love Forth Compatability Notes
------------------------------
Here are some notes on compatibility between single segment forth 83
systems and Love forth.
Storing into CONSTANTs
Old: 0 CONSTANT #flower-pots
44 ' #flower-pots >BODY !
Love: 0 CONSTANT #flower-pots
44 ' #flower-pots TS:>BODY TS:!
In Love Forth, the data cell for CONSTANT is stored in the thread
Segment. TS:! is like ! and TS:>BODY is like >BODY but are directed
to the thread segment.
Revectoring
Old: : PRINTER-EMIT PRN1-EMIT ;
' COM1-EMIT ' PRINTER-EMIT >BODY !
(where PRN1-EMIT and COM1-EMIT have been previously defined)
Love: ' COM1-EMIT ' PRINTER-EMIT TS:>BODY TS:!
In Love Forth the threaded addresses are changed/stored with TS:! .
Note that revectoring can more easily be accomplished with the
revecoring word set (REDEFINE, RESTORE, MAKE_DYNAMIC, GETVECTOR,
etc). See the documentation of these words for more information.
Adding code to the dictionary
Sometimes in compiler words, code or branching offsets are
added to the dictionary with , . This cannot be used in L.O.V.E. Forth
as , (comma) adds to the variable segment (VS:). To add to the
thread segment the word TS:, is used.
For example:
: AGAIN COMPILE BRANCH , ; IMMEDIATE
becomes:
: AGAIN COMPILE BRANCH TS:, ; IMMEDIATE
COMPILE and [COMPILE] perform their expected functions.
Compiler words using these will work in L.O.V.E. Forth as in other
forths. Note that the following standard words are also implemented,
to make control structures easy: <MARK <RESOLVE >MARK >RESOLVE
CREATE - DOES>
In standard Forth CREATE DOES> words are used both for defining data
structures and for defining run time words (such as CASE statements).
These functions are destinct in Love Forth.
CREATE DOES> pair at run time returns an address in the VS: as a
parameter field for data storage uses, CREATE: DOES:> pair at
run-time returns an address in the TS: for use in defining control
structures etc.
Example 1.
( word to create a byte array )
: CARRAY CREATE ALLOT ( comp time: n -- )
DOES> + ; ( run time: n -- addr )
20 CARRAY flower-power
20 CARRAY flower-tower
5 flower-power C@ 19 flower-tower C! ( set location 19)
Here there is no change from other standard Forths.
Example 2.
( a word to make case statements )
( it works by fetching a spec'd thread to execute )
: CASE: CREATE: ] SMUDGE ( comp time: -- )
DOES:> SWAP 2* + TS:@ EXECUTE ; ( run time: n -- )
CASE: FLOWER-TYPES
PETUNIA ROSE DANDYLION CHRYSANTHEMUM ;
Here the CREATE: DOES:> pair and TS:@ replace the CREATE DOES>
and @ from standard Forth.
Example 3.
Note that CREATE alone can still be used for data storage,
as in other Forths
CREATE #leaves-per-flower
4 C, 5 C, 1 C, 27 C, 102 C, 7 C,
#leaves-per-flower 4 + C@ . ( would print 102 )
However if CREATE is used for compiling a list of threads
CREATE: must be used, and access must be made with TS:@.
CREATE: FLOWER-DESCRIPTIONS ]
PERRYWINKLE BATCHELORS-BUTTON FORGET-ME-NOT [
FLOWER-DESCRIPTIONS 2+ TS:@ EXECUTE
CREATE: and TS:@ replace CREATE and @ from standard Forth.
Example 4.
Love Forth always allots VARIABLEs and DVARIABLEs on an even
byte boundary (in VS:). This means that HERE may be increased
by an extra byte on occation. To disable this, simply
re-define VARIABLE and DVARIABLE:
: VARIABLE CREATE 2 ALLOT ;
: DVARIABLE VARIABLE 2 ALLOT ;